
import javax.swing.*;

import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;

public class UnmortgageDialog extends JDialog implements ActionListener {
	
	JButton doIt, cancel;
	JPanel panel;
	int startingCash;
	IntContainer totalCost;
	
	static int remainingCash;
	Player currentPlayer;
	int returnValue;
	
	ArrayList<BooleanContainer> isMortgagedDarkPurple, isMortgagedLightBlue, isMortgagedLightPurple,
	 isMortgagedOrange,isMortgagedRed,isMortgagedYellow,isMortgagedGreen,
	 isMortgagedDarkBlue,isMortgagedUtility, isMortgagedRailroad;
	
	UnmortgageDialog(Player p){
		
		currentPlayer = p;
		returnValue = -1;
		startingCash = currentPlayer.getCash();
		totalCost = new IntContainer(0);
		remainingCash = currentPlayer.getCash();
		
		isMortgagedDarkPurple = new ArrayList(2);
		isMortgagedLightBlue = new ArrayList(3);
		isMortgagedLightPurple = new ArrayList(3);
		isMortgagedOrange = new ArrayList(3);
		isMortgagedRed = new ArrayList(3);
		isMortgagedYellow = new ArrayList(3);
		isMortgagedGreen = new ArrayList(3);
		isMortgagedDarkBlue = new ArrayList(2);
		isMortgagedRailroad = new ArrayList(4);
		isMortgagedUtility = new ArrayList(2);
		
		
		
		currentPlayer.addNewProperty("MediterraneanAve");
		currentPlayer.addNewProperty("BalticAve");//they're purple color, only 2 properties
		//this.currentPlayer.buildHouse("MediterraneanAve", 4);
		//this.currentPlayer.buildHouse("BalticAve", 4);
		//this.currentPlayer.buildHotel("MediterraneanAve");
		//this.currentPlayer.mortgage("MediterraneanAve");
		
		//this.currentPlayer.mortgage("BalticAve");
		//this.currentPlayer.mortgage("MediterraneanAve");
		
		this.currentPlayer.addNewProperty("NewYorkAve");
		this.currentPlayer.addNewProperty("TennesseeAve");
		this.currentPlayer.addNewProperty("StJamesPlace");
		
		this.currentPlayer.buildHouse("NewYorkAve", 4);
		this.currentPlayer.buildHouse("TennesseeAve", 4);
		this.currentPlayer.buildHouse("StJamesPlace", 3);
		this.currentPlayer.mortgage("NewYorkAve");
		/*this.currentPlayer.mortgage("TennesseeAve");
		
		
		this.currentPlayer.addNewProperty("OrientalAve");
		this.currentPlayer.addNewProperty("VermontAve");
		this.currentPlayer.addNewProperty("ConnecticutAve");
		this.currentPlayer.buildHouse("OrientalAve", 2);
		this.currentPlayer.buildHouse("VermontAve", 1);
		this.currentPlayer.buildHouse("ConnecticutAve", 2);
		
		this.currentPlayer.addNewProperty("PacificAve");
		this.currentPlayer.addNewProperty("NorthCarolinaAve");
		this.currentPlayer.addNewProperty("PennsylvaniaAve");
		this.currentPlayer.buildHouse("PacificAve", 0);
		this.currentPlayer.buildHouse("NorthCarolinaAve", 0);
		this.currentPlayer.buildHouse("PennsylvaniaAve", 0);
		this.currentPlayer.mortgage("PacificAve");
		this.currentPlayer.mortgage("NorthCarolinaAve");
		this.currentPlayer.mortgage("PennsylvaniaAve");
		
		currentPlayer.addNewProperty("ParkPlace");
		currentPlayer.addNewProperty("Boardwalk");
		
		currentPlayer.addNewProperty("WaterWorks");
		currentPlayer.addNewProperty("ElectricCompany");
	    this.currentPlayer.mortgage("ElectricCompany");
		
		currentPlayer.addNewProperty("ReadingRailroad");
		currentPlayer.addNewProperty("ShortLineRailroad");
		//this.currentPlayer.mortgage("ReadingRailroad");
		
		*/
		/*test:showing the initial mortgage state
		for(int i =0; i<currentPlayer.getDarkPurpleSize();i++){
			String name = currentPlayer.getDarkPurpleNameAt(i);
			if(currentPlayer.isMortgaged(name))
				System.out.println(name + " is mortgaged");
			else
				System.out.println(name + " is not mortgaged");
		}
		for(int i =0; i<currentPlayer.getLightBlueSize();i++){
			String name = currentPlayer.getLightBlueNameAt(i);
			if(currentPlayer.isMortgaged(name))
				System.out.println(name + " is mortgaged");
			else
				System.out.println(name + " is not mortgaged");
		}
		for(int i =0; i<currentPlayer.getLightPurpleSize();i++){
			String name = currentPlayer.getLightPurpleNameAt(i);
			if(currentPlayer.isMortgaged(name))
				System.out.println(name + " is mortgaged");
			else
				System.out.println(name + " is not mortgaged");
		}
		for(int i =0; i<currentPlayer.getOrangeSize();i++){
			String name = currentPlayer.getOrangeNameAt(i);
			if(currentPlayer.isMortgaged(name))
				System.out.println(name + " is mortgaged");
			else
				System.out.println(name + " is not mortgaged");
		}
		for(int i =0; i<currentPlayer.getRedSize();i++){
			String name = currentPlayer.getRedNameAt(i);
			if(currentPlayer.isMortgaged(name))
				System.out.println(name + " is mortgaged");
			else
				System.out.println(name + " is not mortgaged");
		}
		for(int i =0; i<currentPlayer.getYellowSize();i++){
			String name = currentPlayer.getYellowNameAt(i);
			if(currentPlayer.isMortgaged(name))
				System.out.println(name + " is mortgaged");
			else
				System.out.println(name + " is not mortgaged");
		}
		for(int i =0; i<currentPlayer.getGreenSize();i++){
			String name = currentPlayer.getGreenNameAt(i);
			if(currentPlayer.isMortgaged(name))
				System.out.println(name + " is mortgaged");
			else
				System.out.println(name + " is not mortgaged");
		}
		for(int i =0; i<currentPlayer.getDarkBlueSize();i++){
			String name = currentPlayer.getDarkBlueNameAt(i);
			if(currentPlayer.isMortgaged(name))
				System.out.println(name + " is mortgaged");
			else
				System.out.println(name + " is not mortgaged");
		}
		for(int i =0; i<currentPlayer.getUtilitySize();i++){
			String name = currentPlayer.getUtilityNameAt(i);
			if(currentPlayer.isMortgaged(name))
				System.out.println(name + " is mortgaged");
			else
				System.out.println(name + " is not mortgaged");
		}
		for(int i =0; i<currentPlayer.getRailroadSize();i++){
			String name = currentPlayer.getRailroadNameAt(i);
			if(currentPlayer.isMortgaged(name))
				System.out.println(name + " is mortgaged");
			else
				System.out.println(name + " is not mortgaged");
		}*/
		
		System.out.println("current total wealth = " + currentPlayer.getTotalWealth());
		
		JLabel totalCostLabel = new JLabel("Total cost: $" + totalCost.intValue());
		JLabel remainingCashLabel = new JLabel("Cash remaining: $" + remainingCash);
		
		setSize(600,600);
		this.setLayout(new BorderLayout());
		
		//showing possible properties to be unmortgaged for testing
		JPanel availableProperties = new JPanel();
    	availableProperties.setLayout(new GridLayout(0,1));
    	
    	if(this.hasProperty() == false){
    		JLabel warning = new JLabel(
					"You have no property.");
			JOptionPane.showMessageDialog(this, warning);
			returnValue = 0;
			this.setVisible(false);
			dispose();
    	}
    	else{
    	boolean canUnmortgageSomeProp = false;/*frag to see if the player has some properies that can be unmortgeged.
        if every property(land, railroad, util) is not mortgaged, nothing can be done.*/
    	for(int i = 0; i< this.currentPlayer.getDarkPurpleSize(); i++){
			String name = currentPlayer.getDarkPurpleNameAt(i);
			this.isMortgagedDarkPurple.add(new BooleanContainer(currentPlayer.isMortgaged(name)));
			if(currentPlayer.isMortgaged(name) == true){
				canUnmortgageSomeProp = true;
				availableProperties.add(new UnmortgageProp(currentPlayer, totalCost ,remainingCash, name, totalCostLabel,
					remainingCashLabel, isMortgagedDarkPurple.get(i)));
			}
		}
    	for(int i = 0; i< this.currentPlayer.getLightBlueSize(); i++){
			String name = currentPlayer.getLightBlueNameAt(i);
			this.isMortgagedLightBlue.add(new BooleanContainer(currentPlayer.isMortgaged(name)));
			if(currentPlayer.isMortgaged(name) == true){
				availableProperties.add(new UnmortgageProp(currentPlayer, totalCost ,remainingCash, name, totalCostLabel,
					remainingCashLabel, isMortgagedLightBlue.get(i)));
				canUnmortgageSomeProp = true;
			}
		}
    	for(int i = 0; i< this.currentPlayer.getLightPurpleSize(); i++){
			String name = currentPlayer.getLightPurpleNameAt(i);
			this.isMortgagedLightPurple.add(new BooleanContainer(currentPlayer.isMortgaged(name)));
			if(currentPlayer.isMortgaged(name) == true){
				availableProperties.add(new UnmortgageProp(currentPlayer, totalCost ,remainingCash, name, totalCostLabel,
					remainingCashLabel, isMortgagedLightPurple.get(i)));
					canUnmortgageSomeProp = true;
			}
		}
    	for(int i = 0; i< this.currentPlayer.getOrangeSize(); i++){
			String name = currentPlayer.getOrangeNameAt(i);
			this.isMortgagedOrange.add(new BooleanContainer(currentPlayer.isMortgaged(currentPlayer.getOrangeNameAt(i))));
			if(currentPlayer.isMortgaged(currentPlayer.getOrangeNameAt(i)) == true){
				availableProperties.add(new UnmortgageProp(currentPlayer, totalCost ,remainingCash, name, totalCostLabel,
					remainingCashLabel, isMortgagedOrange.get(i)));
				canUnmortgageSomeProp = true;
			}
		}
    	for(int i = 0; i< this.currentPlayer.getRedSize(); i++){
			String name = currentPlayer.getRedNameAt(i);
			this.isMortgagedRed.add(new BooleanContainer(currentPlayer.isMortgaged(currentPlayer.getRedNameAt(i))));
			if(currentPlayer.isMortgaged(currentPlayer.getRedNameAt(i)) == true){
				availableProperties.add(new UnmortgageProp(currentPlayer, totalCost ,remainingCash, name, totalCostLabel,
					remainingCashLabel, isMortgagedRed.get(i)));
				canUnmortgageSomeProp = true;
			}
		}
    	for(int i = 0; i< this.currentPlayer.getYellowSize(); i++){
			String name = currentPlayer.getYellowNameAt(i);
			this.isMortgagedYellow.add(new BooleanContainer(currentPlayer.isMortgaged(currentPlayer.getYellowNameAt(i))));
			if(currentPlayer.isMortgaged(currentPlayer.getYellowNameAt(i)) == true){
				availableProperties.add(new UnmortgageProp(currentPlayer, totalCost ,remainingCash, name, totalCostLabel,
					remainingCashLabel, isMortgagedYellow.get(i)));
				canUnmortgageSomeProp = true;
			}
		}
    	for(int i = 0; i< this.currentPlayer.getGreenSize(); i++){
			String name = currentPlayer.getGreenNameAt(i);
			this.isMortgagedGreen.add(new BooleanContainer(currentPlayer.isMortgaged(currentPlayer.getGreenNameAt(i))));
			if(currentPlayer.isMortgaged(currentPlayer.getGreenNameAt(i)) == true){
				availableProperties.add(new UnmortgageProp(currentPlayer, totalCost ,remainingCash, name, totalCostLabel,
					remainingCashLabel, isMortgagedGreen.get(i)));
				canUnmortgageSomeProp = true;
			}
		}
    	for(int i = 0; i< this.currentPlayer.getDarkBlueSize(); i++){
			String name = currentPlayer.getDarkBlueNameAt(i);
			this.isMortgagedDarkBlue.add(new BooleanContainer(currentPlayer.isMortgaged(currentPlayer.getDarkBlueNameAt(i))));
			if(currentPlayer.isMortgaged(currentPlayer.getDarkBlueNameAt(i)) == true){
				availableProperties.add(new UnmortgageProp(currentPlayer, totalCost ,remainingCash, name, totalCostLabel,
					remainingCashLabel, isMortgagedDarkBlue.get(i)));
				canUnmortgageSomeProp = true;
			}
		}
    	for(int i = 0; i< this.currentPlayer.getUtilitySize(); i++){
			String name = currentPlayer.getUtilityNameAt(i);
			this.isMortgagedUtility.add(new BooleanContainer(currentPlayer.isMortgaged(currentPlayer.getUtilityNameAt(i))));
			if(currentPlayer.isMortgaged(currentPlayer.getUtilityNameAt(i)) == true){
				availableProperties.add(new UnmortgageProp(currentPlayer, totalCost ,remainingCash, name, totalCostLabel,
					remainingCashLabel, isMortgagedUtility.get(i)));
				canUnmortgageSomeProp = true;
			}
		}
    	for(int i = 0; i< this.currentPlayer.getRailroadSize(); i++){
			String name = currentPlayer.getRailroadNameAt(i);
			this.isMortgagedRailroad.add(new BooleanContainer(currentPlayer.isMortgaged(currentPlayer.getRailroadNameAt(i))));
			if(currentPlayer.isMortgaged(currentPlayer.getRailroadNameAt(i)) == true){
				availableProperties.add(new UnmortgageProp(currentPlayer, totalCost ,remainingCash, name, totalCostLabel,
					remainingCashLabel, isMortgagedRailroad.get(i)));
				canUnmortgageSomeProp = true;
			}
		}
    	
    	if(canUnmortgageSomeProp == false){//if every prop is not mortgaged, nothing done.
    		JLabel warning = new JLabel(
					"Every property is not mortgaged.");
			JOptionPane.showMessageDialog(this, warning);
			returnValue = 0;
			this.setVisible(false);
			dispose();
    	}
    	else{
    	JScrollPane scroll = new JScrollPane(availableProperties, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    	scroll.setPreferredSize(new Dimension(400, 200));
    	
    	//describe two buttons, Do it(confirm) and cancel
    	JPanel panelWithButtons = new JPanel();
    	doIt = new JButton("Do It!");
    	cancel = new JButton("Cancel");
    	panelWithButtons.add(doIt);
    	panelWithButtons.add(cancel);
    	doIt.addActionListener(this);
        cancel.addActionListener(this);
    	
        //a panel put on the center of the border layout
    	panel = new JPanel();
    	panel.setBackground(Color.pink);
    	panel.add(new JLabel("check the property that you want to unmortgage."));
    	panel.add(scroll);
    	//show the result of the calculation
    	JPanel showCashPanel = new JPanel();
    	showCashPanel.setLayout(new GridLayout(4, 0));
    	showCashPanel.add(new JLabel("Starting cash: $" + startingCash));
    	showCashPanel.add(totalCostLabel);
    	showCashPanel.add(remainingCashLabel);
    	showCashPanel.add(panelWithButtons);//defined above
    	panel.add(showCashPanel);
    	panel.setVisible(true);
    	
    	//putting them altogether
        setSize(600, 300);
        setModal(true);
        setLayout(new BorderLayout(0,0));
        /*JLabel info = new JLabel(new ImageIcon("./menuButtons/smallProperty.JPG"));
        
        add(new JLabel(new ImageIcon("./menuButtons/buildHouseHotel.JPG")), BorderLayout.NORTH);*/
        add(panel, BorderLayout.CENTER);
       // add(info, BorderLayout.WEST);
        
        //info.setPreferredSize(new Dimension(190, 125));
        
        this.setResizable(false);
        this.setLocationRelativeTo(null);
		setVisible(true);
		dispose();
    	}
    	}
	}
	public void actionPerformed(ActionEvent e){
        if(e.getSource() == doIt){
        	
        	returnValue = 1;
        	
        	currentPlayer.subtractCash(this.totalCost.intValue());//update the player's cash.
        	
        	//unmortgaging...
        	for(int i = 0; i<this.currentPlayer.getDarkPurpleSize(); i++){
        		if(this.isMortgagedDarkPurple.get(i).boolValue() == false){//if it is unmortgaged,
        			
        			currentPlayer.unmortgage(currentPlayer.getDarkPurpleNameAt(i));
        		}
        	}
        	
        	for(int i = 0; i<this.currentPlayer.getLightBlueSize(); i++){
        		if(this.isMortgagedLightBlue.get(i).boolValue() == false){//if it is unmortgaged,
        			currentPlayer.unmortgage(currentPlayer.getLightBlueNameAt(i));
        		}
        	}
        	for(int i = 0; i<this.currentPlayer.getLightPurpleSize(); i++){
        		if(this.isMortgagedLightPurple.get(i).boolValue() == false){//if it is unmortgaged,
        			currentPlayer.unmortgage(currentPlayer.getLightPurpleNameAt(i));
        		}
        	}
        	for(int i = 0; i<this.currentPlayer.getOrangeSize(); i++){
        		if(this.isMortgagedOrange.get(i).boolValue() == false){//if it is unmortgaged,
        			currentPlayer.unmortgage(currentPlayer.getOrangeNameAt(i));
        		}
        	}
        	for(int i = 0; i<this.currentPlayer.getRedSize(); i++){
        		if(this.isMortgagedRed.get(i).boolValue() == false){//if it is unmortgaged,
        			currentPlayer.unmortgage(currentPlayer.getRedNameAt(i));
        		}
        	}
        	for(int i = 0; i<this.currentPlayer.getYellowSize(); i++){
        		if(this.isMortgagedYellow.get(i).boolValue() == false){//if it is unmortgaged,
        			currentPlayer.unmortgage(currentPlayer.getYellowNameAt(i));
        		}
        	}
        	for(int i = 0; i<this.currentPlayer.getGreenSize(); i++){
        		if(this.isMortgagedGreen.get(i).boolValue() == false){//if it is unmortgaged,
        			currentPlayer.unmortgage(currentPlayer.getGreenNameAt(i));
        		}
        	}
        	for(int i = 0; i<this.currentPlayer.getDarkBlueSize(); i++){
        		if(this.isMortgagedDarkBlue.get(i).boolValue() == false){//if it is unmortgaged,
        			currentPlayer.unmortgage(currentPlayer.getDarkBlueNameAt(i));
        		}
        	}
        	for(int i = 0; i<this.currentPlayer.getUtilitySize(); i++){
        		if(this.isMortgagedUtility.get(i).boolValue() == false){//if it is unmortgaged,
        			currentPlayer.unmortgage(currentPlayer.getUtilityNameAt(i));
        		}
        	}
        	for(int i = 0; i<this.currentPlayer.getRailroadSize(); i++){
        		if(this.isMortgagedRailroad.get(i).boolValue() == false){//if it is unmortgaged,
        			currentPlayer.unmortgage(currentPlayer.getRailroadNameAt(i));
        		}
        	}
        	System.out.println("total cash = " + currentPlayer.getCash());
        	System.out.println("total wealth = " + currentPlayer.getTotalWealth());
        	
        	/*test:showing the mortgage state after presssing "do it"
    		for(int i =0; i<currentPlayer.getDarkPurpleSize();i++){
    			String name = currentPlayer.getDarkPurpleNameAt(i);
    			if(currentPlayer.isMortgaged(name))
    				System.out.println(name + " is mortgaged");
    			else
    				System.out.println(name + " is not mortgaged");
    		}
    		for(int i =0; i<currentPlayer.getLightBlueSize();i++){
    			String name = currentPlayer.getLightBlueNameAt(i);
    			if(currentPlayer.isMortgaged(name))
    				System.out.println(name + " is mortgaged");
    			else
    				System.out.println(name + " is not mortgaged");
    		}
    		for(int i =0; i<currentPlayer.getLightPurpleSize();i++){
    			String name = currentPlayer.getLightPurpleNameAt(i);
    			if(currentPlayer.isMortgaged(name))
    				System.out.println(name + " is mortgaged");
    			else
    				System.out.println(name + " is not mortgaged");
    		}
    		for(int i =0; i<currentPlayer.getOrangeSize();i++){
    			String name = currentPlayer.getOrangeNameAt(i);
    			if(currentPlayer.isMortgaged(name))
    				System.out.println(name + " is mortgaged");
    			else
    				System.out.println(name + " is not mortgaged");
    		}
    		for(int i =0; i<currentPlayer.getRedSize();i++){
    			String name = currentPlayer.getRedNameAt(i);
    			if(currentPlayer.isMortgaged(name))
    				System.out.println(name + " is mortgaged");
    			else
    				System.out.println(name + " is not mortgaged");
    		}
    		for(int i =0; i<currentPlayer.getYellowSize();i++){
    			String name = currentPlayer.getYellowNameAt(i);
    			if(currentPlayer.isMortgaged(name))
    				System.out.println(name + " is mortgaged");
    			else
    				System.out.println(name + " is not mortgaged");
    		}
    		for(int i =0; i<currentPlayer.getGreenSize();i++){
    			String name = currentPlayer.getGreenNameAt(i);
    			if(currentPlayer.isMortgaged(name))
    				System.out.println(name + " is mortgaged");
    			else
    				System.out.println(name + " is not mortgaged");
    		}
    		for(int i =0; i<currentPlayer.getDarkBlueSize();i++){
    			String name = currentPlayer.getDarkBlueNameAt(i);
    			if(currentPlayer.isMortgaged(name))
    				System.out.println(name + " is mortgaged");
    			else
    				System.out.println(name + " is not mortgaged");
    		}
    		for(int i =0; i<currentPlayer.getUtilitySize();i++){
    			String name = currentPlayer.getUtilityNameAt(i);
    			if(currentPlayer.isMortgaged(name))
    				System.out.println(name + " is mortgaged");
    			else
    				System.out.println(name + " is not mortgaged");
    		}
    		for(int i =0; i<currentPlayer.getRailroadSize();i++){
    			String name = currentPlayer.getRailroadNameAt(i);
    			if(currentPlayer.isMortgaged(name))
    				System.out.println(name + " is mortgaged");
    			else
    				System.out.println(name + " is not mortgaged");
    		}*/
        }
        else if(e.getSource() == this.cancel){
        	returnValue = 0;
        }
        resetReturnValue();
		setVisible(false);
		dispose();
    }
	public int getReturnValue(){
		return returnValue;
	}
	public void resetReturnValue(){
		returnValue = -1;
	}
	public boolean hasProperty(){
		if(currentPlayer.getDarkPurpleSize() == 0 &&
				currentPlayer.getLightBlueSize() == 0 &&
				currentPlayer.getLightPurpleSize() == 0 &&
				currentPlayer.getOrangeSize() == 0 &&
				currentPlayer.getRedSize() == 0 &&
				currentPlayer.getYellowSize() == 0 &&
				currentPlayer.getGreenSize() == 0 &&
				currentPlayer.getDarkBlueSize() == 0 &&
				currentPlayer.getUtilitySize() == 0 &&
				currentPlayer.getRailroadSize() == 0){
			return false;
		}
		return true;
	}
}

class UnmortgageProp extends JPanel implements ActionListener{
	
	
	JLabel name;
	JCheckBox propCheckBox;
	JLabel mortgageLabel;
	IntContainer totalCost;
	static int resultCash;
	BooleanContainer isMortgaged;
	Player player;
	String nameOfProperty;
	JLabel totalLabel;
	JLabel remainingCostLabel;
	UnmortgageProp(Player p, IntContainer cost,int cashResult, String str, JLabel totalGainLabel,
			JLabel resultLabel, BooleanContainer Mortgaged){
		player = p;
		totalCost = cost;
		resultCash = cashResult;
		totalLabel = totalGainLabel;
		remainingCostLabel = resultLabel;
		isMortgaged = Mortgaged;
		nameOfProperty = str;
		name = this.adjustName(str);
		
		this.mortgageLabel = new JLabel("Mortgaged");
		
		this.propCheckBox = new JCheckBox("", false);
		propCheckBox.addActionListener(this);
		
		add(mortgageLabel);
		add(propCheckBox);
		add(name);
		
		if(Mortgaged.boolValue() == false)
			this.setVisible(false);
	}
	
	public void actionPerformed(ActionEvent e){
		if(isMortgaged.boolValue() == true){//if it is mortgaged
			isMortgaged.setBoolValue(false);
			totalCost.setIntValue(totalCost.intValue() + player.getMortgageValue(nameOfProperty));
			resultCash -= player.getMortgageValue(nameOfProperty);
			totalLabel.setText("Total cost: $" + totalCost.intValue());
			remainingCostLabel.setText("Cash remaining: $" + resultCash);
			
		}
		else{
			isMortgaged.setBoolValue(true);
			totalCost.setIntValue(totalCost.intValue() - player.getMortgageValue(nameOfProperty));
			resultCash -= player.getMortgageValue(nameOfProperty);
			totalLabel.setText("Total cost: $" + totalCost.intValue());
			remainingCostLabel.setText("Cash remaining: $" + resultCash);
		}
	}
	public JLabel adjustName(String str){
		JLabel adjustedName = new JLabel();
		if(str == "MediterraneanAve"){
			adjustedName = new JLabel("Mediterranean Avenue");
			adjustedName.setForeground(Color.getHSBColor((float)0.9,(float)0.9,(float)0.7));
		}
		else if (str == "BalticAve"){
			adjustedName = new JLabel("       Baltic Avenue");
			adjustedName.setForeground(Color.getHSBColor((float)0.9,(float)0.9,(float)0.7));
		}
		else if (str == "OrientalAve"){
			adjustedName = new JLabel("     Oriental Avenue");
			adjustedName.setForeground(Color.getHSBColor((float)0.6,(float)1,(float)1));
		}
		else if (str == "VermontAve"){
			adjustedName = new JLabel("      Vermont Avenue");
			adjustedName.setForeground(Color.getHSBColor((float)0.6,(float)1,(float)1));
		}
		else if (str == "ConnecticutAve"){
			adjustedName = new JLabel("  Connecticut Avenue");
			adjustedName.setForeground(Color.getHSBColor((float)0.6,(float)1,(float)1));
		}
		else if (str == "StCharlesPlace"){
			adjustedName = new JLabel("    St.Charles Place");
			adjustedName.setForeground(Color.magenta);
		}
		else if (str == "StatesAve"){
			adjustedName = new JLabel("        States Avenue");
			adjustedName.setForeground(Color.magenta);
		}
		else if (str == "VirginiaAve"){
			adjustedName = new JLabel("     Virginia Avenue");
			adjustedName.setForeground(Color.magenta);
		}
		else if (str == "StJamesPlace"){
			adjustedName = new JLabel("      St.James Place");
			adjustedName.setForeground(Color.orange);
		}
		else if (str == "TennesseeAve"){
			adjustedName = new JLabel("    Tennessee Avenue");
			adjustedName.setForeground(Color.orange);
		}
		else if (str == "NewYorkAve"){
			adjustedName = new JLabel("      NewYork Avenue");
			adjustedName.setForeground(Color.orange);
		}
		else if(str == "KentuckyAve"){
			adjustedName = new JLabel("     Kentucky Avenue");
			adjustedName.setForeground(Color.red);
		}
		else if(str == "IndianaAve"){
			adjustedName = new JLabel("      Indiana Avenue");
			adjustedName.setForeground(Color.red);
		}
		else if(str == "IllinoisAve"){
			adjustedName = new JLabel("     Illinois Avenue");
			adjustedName.setForeground(Color.red);
		}
		else if(str == "AtlanticAve"){
			adjustedName = new JLabel("     Atlantic Avenue");
			adjustedName.setForeground(Color.yellow);
		}
		else if(str == "VentnorAve"){
			adjustedName = new JLabel("      Ventnor Avenue");
			adjustedName.setForeground(Color.yellow);
		}
		else if(str == "MarvinGardens"){
			adjustedName = new JLabel("      Marvin Gardens");
			adjustedName.setForeground(Color.yellow);
		}
		else if(str == "PacificAve"){
			adjustedName = new JLabel("      Pacific Avenue");
			adjustedName.setForeground(Color.green);
		}
		else if(str == "NorthCarolinaAve"){
			adjustedName = new JLabel("NorthCarolina Avenue");
			adjustedName.setForeground(Color.green);
		}
		else if(str == "PennsylvaniaAve"){
			adjustedName = new JLabel(" Pennsylvania Avenue");
			adjustedName.setForeground(Color.green);
		}
		else if(str == "ParkPlace"){
			adjustedName = new JLabel("          Park Place");
			adjustedName.setForeground(Color.blue);
		}
		else if(str == "Boardwalk"){
			adjustedName = new JLabel("           Boardwalk");
			adjustedName.setForeground(Color.blue);
		}
		else if(str == "WaterWorks"){
			adjustedName = new JLabel("Water Works");
			adjustedName.setForeground(Color.darkGray);
		}
		else if(str == "ElectricCompany"){
			adjustedName = new JLabel("Electric Company");
			adjustedName.setForeground(Color.darkGray);
		}
		else if(str == "ReadingRailroad"){
			adjustedName = new JLabel("Reading Railroad");
			adjustedName.setForeground(Color.black);
		}
		else if(str == "B&ORailroad"){
			adjustedName = new JLabel("B&O Railroad");
			adjustedName.setForeground(Color.black);
		}
		else if(str == "ShortLineRailroad"){
			adjustedName = new JLabel("ShortLine Railroad");
			adjustedName.setForeground(Color.black);
		}
		else if(str == "PennsylvaniaRailroad"){
			adjustedName = new JLabel("Pennsylvania Railroad");
			adjustedName.setForeground(Color.black);
		}
		
		return adjustedName;
	}
}
